<html>
<head>
<style>
  .ace_editor {
    border: 0;
    width: auto;
    height: 100%;
    margin: 0;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index: 10000;
    touch-action: none;
  }

  body {
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    -ms-overflow-style: scrollbar;
  }
</style>
</head>
<body>
<textarea id="source">package com.sencha.gxt.explorer.client.html;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.LinkElement;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.core.client.Style.Anchor;
import com.sencha.gxt.core.client.Style.AnchorAlignment;
import com.sencha.gxt.explorer.client.app.ui.ExampleContainer;
import com.sencha.gxt.explorer.client.model.Example.Detail;
import com.sencha.gxt.widget.core.client.button.IconButton.IconConfig;
import com.sencha.gxt.widget.core.client.button.ToolButton;
import com.sencha.gxt.widget.core.client.container.CenterLayoutContainer;
import com.sencha.gxt.widget.core.client.container.FlowLayoutContainer;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem;

public class MatericalDesignButtonExample implements IsWidget, EntryPoint {

  public interface MaterialButtonResources extends ClientBundle {
    public static MaterialButtonResources INSTANCE = GWT.create(MaterialButtonResources.class);

    public interface MaterialButtonStyles extends CssResource {
      String toolButton();

      String toolButtonOver();
    }

    @Source({ "material-button-styles.gss" })
    MaterialButtonStyles styles();
  }

  protected static final int MIN_HEIGHT = 410;
  protected static final int MIN_WIDTH = 515;
  
  private CenterLayoutContainer centerLayoutContainer;

  

  @Override
  public Widget asWidget() {
    if (centerLayoutContainer == null) {
      // only needed once
      MaterialButtonResources.INSTANCE.styles().ensureInjected();
      
      // attach material resources
      LinkElement link = Document.get().createLinkElement();
      link.setHref("https://fonts.googleapis.com/icon?family=Material+Icons");
      link.setRel("stylesheet");
      Document.get().getElementsByTagName("head").getItem(0).appendChild(link);

      ToolButton button1 = createMaterialButton("menu", "blue", 36);
      ToolButton button2 = createMaterialButton("more_vert", "green", 36);
      ToolButton button3 = createMaterialButton("error_outline", "red", 36);

      FlowLayoutContainer toolbar = new FlowLayoutContainer();
      toolbar.getElement().getStyle().setBackgroundColor("white");
      toolbar.setBorders(true);
      toolbar.setHeight("38px");
      toolbar.add(button1);
      toolbar.add(button2);
      toolbar.add(button3);
      
      centerLayoutContainer = new CenterLayoutContainer();
      centerLayoutContainer.add(toolbar);
    }
    return centerLayoutContainer;
  }

  /**
   * Sizing: https://google.github.io/material-design-icons/#sizing
   */
  public ToolButton createMaterialButton(String iconName, String color, int size) {
    // define the styles for the button
    String toolStyle = MaterialButtonResources.INSTANCE.styles().toolButton();
    String toolOverStyle = MaterialButtonResources.INSTANCE.styles().toolButtonOver();

    // setup the tool button config
    IconConfig toolConfig = new IconConfig(toolStyle, toolOverStyle);

    // instantiate the button for use
    final ToolButton button = new ToolButton(toolConfig);
    button.setPixelSize(size, size);
    button.addStyleName("material-icons");
    button.addStyleName("md-" + size);
    button.getElement().getStyle().setFontSize(size, Unit.PX);
    button.getElement().getStyle().setColor(color);
    button.getElement().setInnerText(iconName);
    button.addSelectHandler(new SelectHandler() {
      @Override
      public void onSelect(SelectEvent event) {
        fireSelectEvent(button);
      }
    });

    return button;
  }

  protected void fireSelectEvent(ToolButton button) {
    Menu menu = new Menu();
    menu.add(new MenuItem("Item 1"));
    menu.add(new MenuItem("Item 2"));
    menu.add(new MenuItem("Item 3"));
    menu.add(new MenuItem("Item 4"));
    menu.add(new MenuItem("Item 5"));

    // Align Menu to button
    AnchorAlignment alignTo = new AnchorAlignment(Anchor.TOP_LEFT, Anchor.BOTTOM_LEFT, true);
    menu.show(button.getElement(), alignTo, 0, 0);
  }

  @Override
  public void onModuleLoad() {
    new ExampleContainer(this).setMinHeight(MIN_HEIGHT).setMinWidth(MIN_WIDTH).doStandalone();
  }

}
</textarea>

<script src="../../samples/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  var type = "{type}";
  if (type == ("{" + "type}")) {
    // something went wrong, use java as default
    type = "java";
  }
  var editor = ace.edit("source");
  var mode = "ace/mode/" + type;
  var theme = "ace/theme/chrome";
  var readOnly = true;
  editor.getSession().setMode(mode);
  editor.getSession().setUseWorker(false);
  editor.setTheme(theme);
  editor.setShowPrintMargin(false);
  editor.renderer.setShowGutter(true);
  editor.setHighlightActiveLine(false);
  editor.setDisplayIndentGuides(true);
  editor.setReadOnly(readOnly);
  editor.renderer.setPadding(10);
  editor.renderer.setScrollMargin(10, 10, 0, 0);
  editor.getSession().setOptions({
    tabSize: 8,
    useSoftTabs: true,
    useWrapMode: false,
  });
</script>
</body>
</html>